"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var StorageService = /** @class */ (function () {
    function StorageService(props) {
        /** 缓存对象key名称 */
        this.storageKey = '';
        /** 缓存类型 local还是session */
        this.type = '';
        var storageKey = props.storageKey, _a = props.type, type = _a === void 0 ? 'local' : _a;
        this.storageKey = storageKey;
        this.type = type;
        if (type === 'local') {
            var localStore = window.localStorage.getItem(this.storageKey) || '{}';
            window.localStorage.setItem(this.storageKey, localStore);
        }
        else {
            var sessionStore = window.localStorage.getItem(this.storageKey) || '{}';
            window.sessionStorage.setItem(this.storageKey, sessionStore);
        }
    }
    StorageService.prototype.getStorage = function () {
        return (this.type === 'local' ? JSON.parse(window.localStorage.getItem(this.storageKey) || '{}') : JSON.parse(window.sessionStorage.getItem(this.storageKey) || '{}'));
    };
    StorageService.prototype.setStorage = function (storage) {
        if (this.type === 'local') {
            window.localStorage.setItem(this.storageKey, JSON.stringify(storage));
        }
        else {
            window.sessionStorage.setItem(this.storageKey, JSON.stringify(storage));
        }
    };
    /** 根据key获取值 */
    StorageService.prototype.get = function (key) {
        var storage = this.getStorage();
        return storage[key];
    };
    /** 根据key设置值 */
    StorageService.prototype.set = function (key, value) {
        var storage = this.getStorage();
        storage[key] = value;
        this.setStorage(storage);
    };
    /** 根据key删除缓存对象里某个key-value */
    StorageService.prototype.remove = function (key) {
        var storage = this.getStorage();
        var removeStatus = delete storage[key];
        if (removeStatus) {
            this.setStorage(storage);
        }
    };
    /** 清除缓存 */
    StorageService.prototype.clear = function () {
        this.setStorage({});
    };
    return StorageService;
}());
exports.default = StorageService;
